﻿using FluentNHibernate.Mapping;
using UserManagement.DomainEntity;

namespace UserManagement.Dal.NH.Mappings
{
    public class UserCircleMap : ClassMap<UserCircle>
    {
        public UserCircleMap()
        {
            Table("UserCircles");
            Id(x => x.Id).GeneratedBy.Native();
            Map(x => x.Name).Not.Nullable();
            Map(x => x.Comment);
            References(x => x.Owner).Column("OwnerUserAccountId").Not.Nullable();
            HasManyToMany(x => x.UserAccounts)
                .Table("UserCirclesAccounts")
                .ParentKeyColumn("UserCircleId")
                .ChildKeyColumn("UserAccountId")
                .Cascade.All();
        }
    }
}
